package com.nirvana.factory;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.nirvana.MainPanel;
import com.nirvana.config.PluginConfig;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class PanelFactory implements ToolWindowFactory {
    private static final String PROJECT_NAME = "srsc_server2";

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        if (! project.isInitialized()) return;
        if (! Objects.requireNonNull(project.getBasePath()).contains(PROJECT_NAME)) return;

        PluginConfig.init(project);
        ContentFactory instance = ContentFactory.getInstance();
        Content content = instance.createContent(new MainPanel().getMainPanel(), "", false);
        toolWindow.getContentManager().addContent(content);
        ToolWindowManager.getInstance(project).setMaximized(toolWindow, true);
    }
}
